<?php
namespace App\Models\V6;
use DB;
use Illuminate\Http\Request;
use App\Models\V1\MemberModel;


class PartnerModel extends MemberModel{



    /**
     * 获得学习官信息
     * */
    public function get_partner_info($mobile,$appkey){
        $partnerInfo = $this->get_member_info_by_mobile_key($mobile,$appkey);
        if($partnerInfo){
            $colum = [
                'DRPID',
                'SalesMoney',
                'MemBalances',
                'FinishMoney',
                'DRPScale',
                'DRPLevel',
                'IDTree',
                'ParentID',
                'IsRebate',
                'MasterID'
            ];
            $memberNumber = $partnerInfo->MemNumber;
            $info = DB::table('memberdrp')
                ->select($colum)
                ->where('MemNumber',$memberNumber)
                ->where('DeleteMark',1)
                ->first();
            if($info){
                foreach($info as $key => $v){
                    $partnerInfo->$key = $v;
                }
            }
        }
        return $partnerInfo;
    }

    /**
     * 获得默认的支付类型
     * */
    public function get_default_pay_card($memNumber){
        $cardInfo = DB::table('paycard')->where('IsDefault', 1)
            ->where('DeleteMark', 1)
            ->where('MemNumber', $memNumber)
            ->first();
        return $cardInfo;
    }


    /**
     * 添加支付卡
     * */
    public function add_pay_card($data){
        $memberNumber = $data['MemNumber'];
        //检查用户是否已经添加了卡
        $defaultCard = $this->get_default_pay_card($memberNumber);
        if($defaultCard){
            $isDefault = 0;
        }else{
            $isDefault = 1;
        }
        $data['IsDefault']  = $isDefault;
        $result = DB::table('paycard')->insert($data);
        return $result;
    }




}